from django.shortcuts import render
from django.http import HttpResponse
from .models import Book, Category, Ads, Books
from django.core.paginator import Paginator


# Create your views here.
def index(request):
    print(dir(request.user))
    cs = Category.objects.all()
    adss = Ads.objects.all()
    return render(request, "main/index.html", context={"cs": cs, 'adss': adss})


def shiyan(request):
    return render(request, 'main/shiyan.html', context={"name": "huacanke", "age": 22, })


def detail(request, num):
    book = Book.objects.get(id=num)
    return render(request, "main/detail.html", context={'book': book})


def paging(request):
    bs = Books.objects.all()
    paginator = Paginator(bs, 10)
    page = request.GET.get('page', 1)
    bss = paginator.get_page(page)
    return render(request, 'main/paging.html', context={'bss': bss})


def middleware(request):
    return HttpResponse('请求成功')
